<?php

namespace App\Http\Controllers;

use App\Http\Model\Shops;

use Illuminate\Http\Request;

use App\Http\Requests;


use Illuminate\Support\Facades\DB;

class ShopsController extends Controller
{
    /*
     * 搜索店铺
     * num 每页多少数据
     * page  第多少页
     */
    public function SearchShops(Request $request)
    {
        $lat=113.2;
        $lng=22.2;
        $num=10;
        if ($request->has('num')) {
            $num=$request->get('num');
        }
        //$data = HouseDistrict::select(DB::raw('*,round(6378.138*2*asin(sqrt(pow(sin((' . $lat . '*pi()/180-lat*pi()/180)/2),2)+cos(' . $lat . '*pi()/180)*cos(lat*pi()/180)* pow(sin((' . $lng . '*pi()/180-lng*pi()/180)/2),2)))*1000) as distance'));
        $Shops=Shops::select(DB::raw('Id,ShopName,ShopStatus,CreateDate,BusinessSphere,Logo,businessaddress,score,round(6378.138*2*asin(sqrt(pow(sin((' . $lat . '*pi()/180-lat*pi()/180)/2),2)+cos(' . $lat . '*pi()/180)*cos(lat*pi()/180)* pow(sin((' . $lng . '*pi()/180-lng*pi()/180)/2),2)))*1000) as distance'))
                 ->where('ShopStatus','12')
                 ->paginate($num)
                 ->each(function($v,$k){

                 });


        return json_success('1',$Shops);
    }
   public  function  ShopDetails(Request $request){
       $sid='';
       if ($request->has('sid')) {
           $sid=$request->get('sid');
       }else{
           return json_error('店铺id为必填');
       }
       $Shops=Shops::where('Id',$sid)
             ->first();
       if($Shops){
           return json_success('1',$Shops);
       }else{
           return json_error('找不到此店铺信息');
       }
   }
}
